package org.hot100_2;

import org.leetcode.TreeNode;

public class leetcode543 {
    int res =0;
    public int diameterOfBinaryTree(TreeNode root) {

        getDepth(root);
        return res-1;
    }

    private int getDepth(TreeNode root){
        if (root==null){
            return 0;
        }

        int leftDepth = getDepth(root.left);
        int rightDepth = getDepth(root.right);
        res = Math.max(res,leftDepth+rightDepth+1);

        int currDepth =Math.max(leftDepth,rightDepth)+1;
        return currDepth;
    }


}
